package com.linkhub.oms.entity.resulttype.stock;

import cn.hutool.core.util.ObjectUtil;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;

/**
 * @Description: ProductStockResultEntity
 * @Author: echo
 * @Date: 2024/4/26 10:48
 * @Version: 1.0
 */
@Data
public class ProductStockResultEntity implements Serializable {
    public static final Integer DEFAULT_STOCK_COUNT = 0;

    @ApiModelProperty(value = "本地商品skuId")
    private String skuId;

    @ApiModelProperty(value = "sku")
    private String sku;

    @ApiModelProperty(value = "产品名称")
    private String productEnTitle;

    @ApiModelProperty(value = "imgUrl")
    private String imgUrl;

    @ApiModelProperty(value = "spu")
    private String spu;

    @ApiModelProperty(value = "商家名称")
    private String merchantUserName;

    @ApiModelProperty(value = "用户id")
    private String userId;

    @ApiModelProperty(value = "仓库名称")
    private String stashName;

    @ApiModelProperty(value = "实物库存")
    private Integer physicalStock;

    @ApiModelProperty(value = "预占库存")
    private Integer preemptionStock;

    @ApiModelProperty(value = "冻结库存")
    private Integer frozenStock;

    @ApiModelProperty(value = "在途库存")
    private Integer passageStock;

    private Integer goodStock;

    private Integer badStock;

    public Integer computeAvailableStock() {
        int availableStock = ObjectUtil.defaultIfNull(this.getPhysicalStock(), DEFAULT_STOCK_COUNT)
                - ObjectUtil.defaultIfNull(this.getPreemptionStock(), DEFAULT_STOCK_COUNT)
                - ObjectUtil.defaultIfNull(this.getFrozenStock(), DEFAULT_STOCK_COUNT);

        return availableStock;
    }

}
